package com.bw.lyc.mvp.view.mine;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.blankj.utilcode.util.LogUtils;
import com.bumptech.glide.Glide;
import com.bw.lyc.R;
import com.bw.lyc.mvp.model.db.DBManager;
import com.bw.lyc.mvp.model.db.UserEntityDao;
import com.bw.lyc.mvp.model.entity.UserEntity;
import com.bw.lyc.util.StatusBarColorUtils;

public class SettingActivity extends StatusBarColorUtils implements View.OnClickListener {

    private ImageView viewTopBack;
    private ImageView settingHeadimg;
    private ImageView settingImg4;
    private ImageView settingImg5;
    private ImageView settingImg6;
    private boolean flag = true;
    private boolean flag1 = false;
    private boolean flag2 = false;
    private RelativeLayout settingRelative2;
    private RelativeLayout settingRelative3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        initView();
        viewTopBack.setOnClickListener(this::onClick);
        try {
            LogUtils.json(DBManager.getInstance().getDaoSession().loadAll(UserEntity.class));
        } catch (Exception e) {
            e.printStackTrace();
        }
        setStatusBarColor(Color.WHITE);
        UserEntity unique = null;
        try {
            unique = DBManager.getInstance().getDaoSession().queryBuilder(UserEntity.class).where(UserEntityDao.Properties.Id.eq(0)).unique();
        } catch (Exception e) {
            e.printStackTrace();
        }
        String user_img = unique.getUser_img();
        Glide.with(this).load(user_img).circleCrop().into(settingHeadimg);
        viewTopBack.setOnClickListener(this::onClick);
        settingImg4.setOnClickListener(this::onClick);
        settingImg5.setOnClickListener(this::onClick);
        settingImg6.setOnClickListener(this::onClick);
        settingRelative2.setOnClickListener(this::onClick);
        settingRelative3.setOnClickListener(this::onClick);

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.view_top_back) {
            finish();
        }
        if (id == R.id.setting_relative2) {
            startPage(UpdateUserActivity.class);
            finish();
        }
        if (id == R.id.setting_relative3) {
            startPage(SafeActivity.class);
        }
        if (id == R.id.setting_img4) {
            if (flag) {
                flag = false;
                settingImg4.setImageResource(R.mipmap.new_off);
            } else {
                flag = true;
                settingImg4.setImageResource(R.mipmap.new_on);
            }
        }
        if (id == R.id.setting_img5) {
            if (flag1) {
                flag1 = false;
                settingImg5.setImageResource(R.mipmap.new_off);
            } else {
                flag1 = true;
                settingImg5.setImageResource(R.mipmap.new_on);
            }
        }
        if (id == R.id.setting_img6) {
            if (flag2) {
                flag2 = false;
                settingImg6.setImageResource(R.mipmap.new_off);
            } else {
                flag2 = true;
                settingImg6.setImageResource(R.mipmap.new_on);
            }
        }
    }

    private void initView() {
        viewTopBack = (ImageView) findViewById(R.id.view_top_back);
        settingHeadimg = (ImageView) findViewById(R.id.setting_headimg);
        settingImg4 = (ImageView) findViewById(R.id.setting_img4);
        settingImg5 = (ImageView) findViewById(R.id.setting_img5);
        settingImg6 = (ImageView) findViewById(R.id.setting_img6);
        settingRelative2 = (RelativeLayout) findViewById(R.id.setting_relative2);
        settingRelative3 = (RelativeLayout) findViewById(R.id.setting_relative3);
    }

    @Override
    public View addStatusView() {
        return f(R.id.setting_relative);
    }
}